package com.bl.student.dao.repository;

import com.bl.student.dao.model.TeacherEntity;
import com.bl.student.dao.model.UserEntity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * Created by yujingyi on 2018/1/6.
 */
public interface UserRepository extends JpaRepository<UserEntity, String> {

    List<UserEntity> findByMobile(String mobile);

    List<UserEntity> findByHxName(String hxName);

    List<UserEntity> findByUnionId(String unionId);

    List<UserEntity> findByOpenId(String openId);

    List<UserEntity> findByAccount(String account);

    List<UserEntity> findByIdIn(List<String> ids);

    List<UserEntity> findByInviteCode(String inviteCode);

    Page<UserEntity> findAllByOrderByCreateTimeDesc(Pageable pageable);

    Page<UserEntity> findByNicknameContainingOrderByCreateTimeDesc(String nickname, Pageable pageable);

    Page<UserEntity> findByNicknameLikeOrderByCreateTimeDesc(String nickname, Pageable pageable);

    @Query(value = "select * from partyb where if(?1 !='',id=?1,1=1) and if(?2 !='',mobile=?2,1=1)" +
            "and if(?3 !='',nickname=?3,1=1) and if(?4 !='',status=?4,1=1) ORDER BY create_time DESC \n#pageable\n",
            countQuery ="select * from partyb where if(?1 !='',id=?1,1=1) and if(?2 !='',mobile=?2,1=1) and if(?3 !='',nickname=?3,1=1) and if(?4 !='',status=?4,1=1)",
            nativeQuery = true)
    Page <UserEntity>  findMultList(String id, String mobile, String nickname , String status, Pageable pageable );

}
